#include "GameOverScreen.h"
#include "Graphics/GraphicsManager.h"
#include "StarComponents.h"

GameOverScreen::GameOverScreen()
	: Object(),
	m_pSpriteObject(nullptr),
	m_PosY(0),
	m_FallSpeed(200.0f),
	m_bStopFalling(false)
{

}

GameOverScreen::~GameOverScreen()
{
}

void GameOverScreen::Initialize()
{
	AddComponent(new star::SpriteComponent(_T("HUD/ScreenOverlay_DarkGray.png"),_T("Overlay"), true));

	m_pSpriteObject = new star::Object();
	m_pSpriteObject->AddComponent(new star::SpriteComponent(_T("HUD/GameOver.png"), _T("GameOver"), true));
	AddChild(m_pSpriteObject);

	m_PosY = static_cast<float>(star::GraphicsManager::GetInstance()->GetTargetWindowHeight());
	m_pSpriteObject->GetTransform()->Translate(0, m_PosY);
}

void GameOverScreen::Update(const star::Context& context)
{
	m_PosY -= m_FallSpeed * static_cast<float>(context.mTimeManager->GetSeconds());

	if(!m_bStopFalling)
	{
		if(m_PosY < -20.0f)
		{
			m_FallSpeed *= -0.7f;
			m_bStopFalling = true;
		}
	}
	else
	{
		if(m_PosY > 0)
		{
			m_PosY = 0;
		}
	}
	m_pSpriteObject->GetTransform()->Translate(0, m_PosY);
}